<?php
include_once "xAP-functions/webincludes.php";
include_once $config["basefolder"]."/engine/".$config["modulefolder"]."/Timer.php";

set_time_limit(30);  //30seconds max

	$sql="select FullLocation from xAP_Pictures_Item where ItemID=".intval($_GET["id"]);
	$results=dbquery($sql);
	$picpath=$results[0]["FullLocation"];
	$sendpath=$picpath;
	$info=pathinfo($picpath);
	$pichash=sha1($picpath);
	
	if($_GET["type"]==1){
		$sendpath=$config["basefolder"]."tmp/Pictures/Thumbs/".substr($pichash,0,2)."/".substr($pichash,2,2)."/".substr($pichash,4,2)."/".$pichash.".jpg";
		}
	if(!file_exists($sendpath)){
		// thumnail is not there so remake it
		$picpathtmp=str_replace("\\","\\\\",$picpath);
		// turnlogging off to prevent errors going to browser
		$config["debug"]=0;
		//CreateThumbnailImagick($picpathtmp,0);
		//@dbexec("update xAP_Pictures_Item set Thumbnail=1 where ItemID=".intval($_GET["id"]));
	}
	if(file_exists($sendpath)){
		$imagedata=file_get_contents($sendpath);
		$length = strlen($imagedata);
		header('Last-Modified: '.date('r'));
		header('Content-Length: '.filesize($sendpath));
		header('Content-Type: image/jpeg');
		print($imagedata);
	}
	//ob_end_flush();


?>